﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace fApp.Forms
{
    public partial class MoveGrip : fControl
    {
        public Form toForm { get; set; }
        public MoveGrip()
        {
            InitializeComponent();
            this.MouseDown += new MouseEventHandler(MoveGrip_MouseDown);
            this.MouseMove += new MouseEventHandler(MoveGrip_MouseMove);
            this.Dock = DockStyle.Fill;
            toForm = null;
        }

        private Point mousePoint;

        void MoveGrip_MouseMove(object sender, MouseEventArgs e)
        {

            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                toForm.Location = new Point(
                    toForm.Location.X + e.X - mousePoint.X,
                    toForm.Location.Y + e.Y - mousePoint.Y);
            }
        }

        void MoveGrip_MouseDown(object sender, MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                mousePoint = new Point(e.X, e.Y);
            }
        }


        private void MoveGrip_Load(object sender, EventArgs e)
        {
            if(toForm == null)toForm=this.ParentForm;
        }
    }
}
